#pragma GCC optimize(2)
#include <iostream>
#include <algorithm>
#include <cstring>
#include <string>
#include <map>
#include <vector>

using namespace std;
using LL = long long;

int n;
int d0[22], d1[22];

void solve(){
    memset(d0, 0, sizeof d0);
    memset(d1, 0, sizeof d1);

    cin >> n;
    for(int i = 1, x; i <= n; i ++){
        cin >> x;
        // cout << x << " " << "x & 1" << (x & 1) << '\n';



        for(int j = 0; j <= 20; j ++){
            if(x >> j & 1){
                d1[j] ++;         
            }else{
                d0[j] ++;
            }
        }
    }

    // for(int i = 0; i <= 11; i ++) cout << d0[i] << " ";
    // cout << "\n";
    
    // for(int i = 0; i <= 11; i ++) cout << d1[i] << " ";
    // cout << "\n";


    int res = 0;
    for(int i = 0; i <= 20; i ++){
        if(d1[i] && d0[i]){
            res += (1ll << i);
        }
    }

    cout << res << '\n';
}

int main(){
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int T;
    cin >> T;
    while(T--){
        solve();
    }
    return 0;
}